package com.berwin.apkdistribution.view;


import javax.swing.*;
import javax.xml.crypto.Data;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Logger extends JPanel {

    private JLabel lblMessage;
    private JLabel lblStatus;

    private ImageIcon iconRed = new ImageIcon("./res/stat_red.png");
    private ImageIcon iconYellow = new ImageIcon("./res/stat_yellow.png");
    private ImageIcon iconGreen = new ImageIcon("./res/stat_green.png");

    public Logger() {
        this.setLayout(new FlowLayout(FlowLayout.RIGHT));

        this.lblMessage = new JLabel();
//        this.lblMessage.setForeground(Color.GRAY);
        this.lblMessage.setFont(new Font(null, Font.PLAIN, 8));
        this.add(this.lblMessage);

        this.lblStatus = new JLabel(iconGreen);
        this.add(this.lblStatus);
    }

    public void logInfo(String message) {
//        this.lblMessage.setForeground(Color.GREEN);
        this.lblMessage.setText(this.getTime() + message);
        this.lblStatus.setIcon(iconGreen);
    }

    public void logWarn(String message) {
//        this.lblMessage.setForeground(Color.YELLOW);
        this.lblMessage.setText(this.getTime() + message);
        this.lblStatus.setIcon(iconYellow);
    }

    public void logError(String message) {
//        this.lblMessage.setForeground(Color.RED);
        this.lblMessage.setText(this.getTime() + message);
        this.lblStatus.setIcon(iconRed);
    }

    public String getTime() {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
        return f.format(new Date());
    }


}
